package cn.lg.soar.system.biz.modules.auth.model;

import cn.lg.soar.common.model.base.TreeDTO;
import cn.lg.soar.core.annotations.constraints.group.Create;
import cn.lg.soar.core.annotations.constraints.group.Update;
import cn.lg.soar.system.biz.modules.auth.entity.Role;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

import java.util.Set;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class RoleDto extends TreeDTO {

    @NotNull(message = "id不能为空", groups = {Update.class})
    @Min(value = 0, message = "id不能小于0", groups = {Update.class})
    @Schema(description = "主键id")
    private Long id;

    @NotBlank(message = "角色编码不能为空", groups = {Create.class})
    private String code;

    private Integer type;

    @NotBlank(message = "角色名不能为空", groups = {Create.class})
    private String name;

    private String alias;

    @Schema(description = "备注")
    private String remark;

    private Set<Integer> menuIds;

    public RoleDto() {
    }

    public RoleDto(Role source) {
        this.id = source.getId();
        this.code = source.getCode();
        this.type = source.getType();
        this.name = source.getName();
        this.alias = source.getAlias();
        this.remark = source.getRemark();
        this.setVersion(source.getVersion());
        this.setParentId(source.getParentId());
        this.setCreateTime(source.getCreateTime());
        this.setUpdateTime(source.getUpdateTime());
    }

    public Role toRole() {
        Role target = new Role();

        target.setId(this.id);
        target.setCode(this.code);
        target.setType(this.type);
        target.setName(this.name);
        target.setAlias(this.alias);
        target.setRemark(this.remark);
        target.setParentId(this.getParentId());
        target.setCreateTime(this.getCreateTime());
        target.setUpdateTime(this.getUpdateTime());
        target.setVersion(this.getVersion());
        return target;
    }
}
